package com.hsnn.medstgmini.base.dict.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hsnn.medstgmini.base.dict.dao.DicHosptypeDao;
import com.hsnn.medstgmini.base.dict.model.DicHosptype;
import com.hsnn.medstgmini.base.dict.service.DicHosptypeManager;
import com.hsnn.medstgmini.util.Pagination;

@Service
@Transactional
public class DicHosptypeManagerImpl implements DicHosptypeManager {

	@Autowired
	private DicHosptypeDao dicHospTypeDao;
	
	@Override
	public List<DicHosptype> queryCheHosptypeByFatherId(String fatherId) {
		return dicHospTypeDao.getChildList(fatherId);
	}

	@Override
	public Pagination getDicHospTypeList(Pagination page){
		return dicHospTypeDao.getDicHospTypeList(page);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public Pagination getDicHospTypeLogList(Pagination page){
		List<Object[]> list =  (List<Object[]>) dicHospTypeDao.getDicHospTypeLogList(page).getRows();
		List<Map<String,String>> data = new ArrayList<Map<String,String>>();
		if(list.size()>0){
			for(int i = 0;i<list.size();i++){
				Map<String,String> map = new HashMap<String, String>();
				Object[] obj = list.get(i);
				map.put("fatherHospTypeCode", obj[0]==null?obj[2].toString():obj[0].toString());
				map.put("fatherHospType", obj[0]==null?obj[3].toString():obj[1].toString());
				map.put("hospTypeCode", obj[0]==null?"":obj[2].toString());
				map.put("hospType", obj[0]==null?"":obj[3].toString());
				map.put("status", obj[4]==null?"":obj[4].toString());
				map.put("updUser", obj[5]==null?"":obj[5].toString());
				map.put("updDatetime", obj[6]==null?"":obj[6].toString());
				map.put("logId", obj[7]==null?"":obj[7].toString());
				map.put("detail", obj[8]==null?"":obj[8].toString());
				data.add(map);
			}
			page.setRows(data);
		}
		return page;
	}
	
	
	/**
	 * 基础库 数据字典 医疗机构类别字典 根据id查询 医疗机构类别 日志详情
	 * @param page
	 * @return
	 */
	@Override
	public List<Map<String, Object>> getDicHosptypeLogDetail(Pagination page) {
		return dicHospTypeDao.getDicHosptypeLogDetail(page);
	}
	
	
	/**
	 * 
	 *@category 停用启用（状态改变）
	 *@author wangbing
	 *@date 2015年6月9日
	 *void
	 */
	@Transactional
	@Override
	public void changeStatus(DicHosptype dicHosptype) {
		dicHospTypeDao.changeStatus(dicHosptype);
	}
	
	@Transactional
	@Override
	public Pagination initEdit(Pagination page){
		return dicHospTypeDao.initEdit(page);
	}
	
	@Transactional
	@Override
	public void updateHospType(Pagination page) {
		dicHospTypeDao.updateHospType(page);
		
	}
	
	@Transactional
	@Override
	public void addHospType(Pagination page) {
		dicHospTypeDao.addHospType(page);
		
	}
	/**
	 * 根据code或name查看有无重复数据
	 * @param code,name
	 * @return
	 */
	@Override
	public List<DicHosptype> getHospTypeBy(String key,String value,String hospTypeId) {
		return dicHospTypeDao.getHospTypeBy(key,value,hospTypeId);
	}

	/**
	 * 根据条件获取不分页数据
	 * @param page
	 * @return page
	 */
	@Override
	public Pagination getDicHospTypeNoPage(Pagination page){
		return dicHospTypeDao.getDicHospTypeNoPage(page);
	}

}
